let db = require('./index')
exports.login = (req, res) => {
    let sql = 'select uid,username,password from `userdata` where username=? and password=?'
    db.query(sql, [req.query.username, req.query.password], (err, data) => {
        if (err) {
            return res.send({
                status: 400,
                message: "登录失败"
            })
        }
        if (data.length > 0) {
            res.send({
                status: 200,
                message: "登录成功",
                data: { uid: data[0].uid }
            })
        } else {
            res.send({
                status: 202,
                message: "用户名或者密码错误"
            })
        }

    })
}
exports.menuData = (req, res) => {
    let sql = 'select * from menudata'
    db.query(sql, (err, data) => {
        if (err) {
            return res.send({
                status: 400,
                message: "数据获取失败"
            })
        }
        res.send(data)
    })
}
exports.BusinessStatus = (req, res) => {
    let sql = 'select * from businessstatus'
    db.query(sql, (err, data) => {
        if (err) {
            return res.send({
                status: 400,
                message: "数据获取失败"
            })
        }
        res.send(data)
    })
}
exports.documentstatus = (req, res) => {
    let sql = 'select * from documentstatus'
    db.query(sql, (err, data) => {
        if (err) {
            return res.send({
                status: 400,
                message: "数据获取失败"
            })
        }
        res.send(data)
    })
}
exports.getDetail = (req, res) => {
    let sql = 'select * from `getdetail`'
    db.query(sql, (err, data) => {
        if (err) {
            return res.send({
                status: 400,
                message: "数据获取失败"
            })
        }
        res.send({
            status: 200,
            message: "数据获取成功",
            data
        })
    })
}
exports.getDetailIdData = (req, res) => {
    let sql = 'select * from getdetail where wmCode = ? or invCode = ? or invName = ? '
    db.query(sql, [req.query.wmCode, req.query.invCode, req.query.invName], (err, data) => {
        if (err) {
            return res.send({
                status: 400,
                message: "查询失败"
            })
        }
        res.send(data)
    })
}
exports.examineGetDetail = (req, res) => {
    let sql = "update getdetail set params=json_set(params,'$.sisName',sisName=?) where id=?"
    db.query(sql, [req.juery.sisName, req.juery.id], (err, data) => {
        if (err) {
            return res.send({
                status: 400,
                message: "操作失败"
            })
        }
        if (data.changedRows > 0) {
            res.send({
                status: 200,
                message: "更新成功"
            })
        } else {
            res.send({
                status: 202,
                message: "更新失败"
            })
        }
    })
}